package PaperExperiment;

import java.util.ArrayList;

public class Rule {
	public CellGroup gIn = null;
	public CellGroup gOut = null;
	public ArrayList<Cell> listPassCell = null;
	
	private final int thresholdMinMatch = 8;
	
	public Rule(CellGroup gIn, CellGroup gOut) {
		this.listPassCell = new ArrayList<Cell>();
		this.gIn = gIn;
		this.gOut = gOut;
	}
	
	public void ACT001_addCell(Cell c) {
		if(!this.listPassCell.contains(c)) {
			this.listPassCell.add(c);
		}
	}
	
	public boolean ACT002_isBelongPassGroup(Cell c) {
		boolean isFound = false;
		int index = 0;
		while(!isFound && index < this.listPassCell.size()) {
			if(this.listPassCell.get(index).row == c.row && this.listPassCell.get(index).col == c.col) {
				isFound = true;
			}
			index = index + 1;
		}
		return isFound;
	}
	
	public boolean ACT003_isBelongRule(TrajRegion traj) {
		int count = 2;
		if(this.gIn.ACT003_isBelongGroup(traj.listCoverCellSeqly.get(0)) &&
		   this.gOut.ACT003_isBelongGroup(traj.listCoverCellSeqly.get(traj.listCoverCellSeqly.size() - 1))) {
			int index = 1;
			while(index < traj.listCoverCellSeqly.size() - 1) {
				if(this.ACT002_isBelongPassGroup(traj.listCoverCellSeqly.get(index))) {
					count = count + 1;
				}
				index = index + 1;
			}
		}
		return (count >= this.thresholdMinMatch);
	}
}